import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-12-23
 * Time:20:54
 */
class Student{
    public int studentId;
    public String studentName;
}
@WebServlet("/getjackson")
public class JacksonServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ObjectMapper objectMapper=new ObjectMapper();
        Student s=objectMapper.readValue(req.getInputStream(),Student.class);
        System.out.println(s.studentId);
        System.out.println(s.studentName);
        resp.setContentType("text/html;charset=utf8");
        resp.getWriter().write(s.studentId+":"+s.studentName);
    }
}
